Comment = require('../models/comment')

#comment
exports.save = (req, res) ->
  _comment = req.body.comment
  movieId = _comment.movie
  comment = new Comment(_comment)
  if _comment.cid
    await Comment.findById _comment.cid, defer err, comment
    reply = {
      from: _comment.from,
      to: _comment.tid,
      content: _comment.content
    }
    comment.reply.push(reply)
    await comment.save defer err, comment
    console.log err if err
    res.redirect '/movie/' + movieId
  else
    comment = new Comment(_comment)
    await comment.save defer err, comment
    console.log err if err
    res.redirect '/movie/' + movieId
